﻿#Include ..\baseHandle.ahk

class Run_ extends BaseHandle {

  static Handle(parsed) {
    option := parsed.kvparams['t'] || ''
    cfs := MeowConf.Of('./cfg/runFile.txt')
    if r := cfs.Get(parsed.target) {
      Run(r, Path.Dir(r), option) ; 设置目录，因为很多程序会输出日志等文件
      return this.Succ('ok, run custom', 'x')
    }
    try Run(parsed.target, , option?)
    catch
      return this.Fail('failure to run')
    return this.Succ('ok', 'x')
  }

  static Spec() {
    return {
      cmd: 'run',
      desc: '包装原生Run方法',
      format: 'run [-t=min|max|hide] <target>',
      args: {
        desc: '',
        isOptional: false,
        cacheable: true,
        generator: {
          script: '',
          postProcess: (*) => MeowConf.Of('./cfg/runFile.txt').data.keys
        }
      },
      extra: {
        isEnable: false,
      }
    }
  }

}